{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Line Fit slope =  [0.48581043 0.54790823 0.68101747]\n",
      "Plan Fit normal= [-0.13915877 -0.61049055  0.77970259]\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c26dc405917d4eca9c9b1a98311fa976",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[4.5, 4.5, 4.5, 0.0, 0.0, 0.0, 1.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Usage example of fitLine() and fitPlane()\n",
    "\n",
    "Draw a line in 3D that fits a cloud of 20 Points,\n",
    "Show the first set of 20 points and fit a plane to them.\n",
    "\"\"\"\n",
    "from __future__ import division, print_function\n",
    "import numpy as np\n",
    "from vtkplotter import *\n",
    "\n",
    "# declare the class instance\n",
    "vp = Plotter()\n",
    "\n",
    "# draw 500 fit lines superimposed and very transparent\n",
    "for i in range(25):\n",
    "\n",
    "    x = np.linspace(-2, 5, 20)  # generate each time 20 points\n",
    "    y = np.linspace(1, 9, 20)\n",
    "    z = np.linspace(-5, 3, 20)\n",
    "    data = np.array(list(zip(x, y, z)))\n",
    "    data += np.random.normal(size=data.shape) * 0.8  # add gauss noise\n",
    "\n",
    "    vp += fitLine(data).lw(1)  # fit a line\n",
    "\n",
    "# 'data' still contains the last iteration points\n",
    "vp += Points(data, r=2, c=\"yellow\")\n",
    "\n",
    "# the first fitted slope direction is stored\n",
    "# in actor.info['slope] and actor.info['normal]\n",
    "print(\"Line Fit slope = \", vp.actors[0].info[\"slope\"])\n",
    "\n",
    "plane = fitPlane(data)  # fit a plane\n",
    "print(\"Plan Fit normal=\", plane.info[\"normal\"])\n",
    "\n",
    "vp += plane\n",
    "\n",
    "vp.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
